package com.songlanyun.modules.account.controller.common;


import com.songlanyun.common.annotation.RepeatSubmit;
import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.common.utils.R;
import com.songlanyun.common.utils.StatusMsgEnum;
import com.songlanyun.modules.account.model.dto.VerifyCodeDTO;
import com.songlanyun.modules.account.service.CommonService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 会员帐号表（会员的基本信息与关系）
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-02 15:51:10
 */
@RestController
@RequestMapping("api/common/account")
public class CommonController {

    @Resource
    private CommonService commonService;

    /**
     * 获取验证码
     *
     * @param mobile 手机号
     * @return
     */
    @RepeatSubmit(value = "5")
    @PostMapping("/getVerfityCode")
    public R getVerfityCode(@RequestBody String mobile) {
        //发送验证码短信
        boolean b = commonService.getVerfityCode(mobile);

        if (b) {
            return R.ok(StatusMsgEnum.SUCCESS.getMsg());
        } else {
            return R.error(StatusMsgEnum.SMSCODESEND_FAIL);
        }
    }

    /**
     * 获取验证码, 含入参
     *
     * @return
     */
    @RepeatSubmit(value = "5")
    @PostMapping("/getVerifyCodeByParam")
    public R getVerifyCodeByParam(@RequestBody VerifyCodeDTO dto) {
        boolean b = commonService.getVerifyCodeByParam(dto);
        if (b) {
            return R.ok(StatusMsgEnum.SUCCESS.getMsg());
        } else {
            return R.error(StatusMsgEnum.SMSCODESEND_FAIL);
        }
    }
}
